package com.boho.ecp.manage.product.dao;

import java.sql.Connection;

import org.apache.commons.lang.StringUtils;

import cn.boho.framework.po.CQuery;
import cn.boho.framework.po.CQueryFactoryTool;
import cn.boho.framework.po.ComboPager;
import cn.boho.framework.po.DAO;
import cn.boho.framework.po.Pager;

public class ProductDao extends DAO {

	public static ComboPager queryProductPager(Connection con, Pager pager, String productName, String status) throws Exception{
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_PRODUCT where IS_VALID = 1 ");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		int i = 0;
		if(StringUtils.isNotBlank(productName)){
			sql.append(" and lower(PRODUCT_NAME) like ?");
			query.setString(++i, "%" + productName.toLowerCase() + "%");
		}
		if(StringUtils.isNotBlank(status)){
			sql.append(" and PRODUCT_STATUS = ?");
			query.setString(++i, status);
		}
		sql.append(" order by PRODUCT_NO desc");
		query.setCommand(sql.toString());
		return query.getDynaBeanMapComboPager("T_PRODUCT", pager, con);
	}
	
}
